package xkp.lesson1;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",8888);
        InputStream inputStream = socket.getInputStream();
        byte[] buf = new byte[1024*1024];
        int length = 0;
        int sum = 0;
        //判断是否读取到流结尾依然是使用read的返回值如果是-1，则表示读取到流结尾。
        while ((length = inputStream.read(buf)) != -1) {
            System.out.println("读取数据");
            sum += length;
        }
        System.out.println(sum);
        inputStream.close();
        socket.close();
    }
}
